export default {
  namespaced: true,
  state() {
    return {
      token: uni.getStorageSync('token') || '',
      address: JSON.parse(uni.getStorageSync('address') || '{}'),
      userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
      // 重定向的信息对象，包含属性： { url, type }
      redirectInfo: null
    }
  },
  getters: {
    fullAddress(state) {
      const { provinceName, cityName, countyName, detailInfo } = state.address;
      return provinceName + cityName + countyName + detailInfo;
    },
  },
  mutations: {
    // 1. 存储地址
    setAddress(state, address) {
      state.address = address
      uni.setStorageSync('address', JSON.stringify(address))
    },
    // 2. 存储用户信息
    setUserInfo(state, userinfo) {
      state.userinfo = userinfo
      uni.setStorageSync('userinfo', JSON.stringify(userinfo))
    },
    // 3. 存储token
    setToken(state, token) {
      state.token = token || ''
      uni.setStorageSync('token', token)
    },
    // 4. 存储重定向信息
    setRedirectInfo(state, info) {
      state.redirectInfo = info
    }
  },
  actions: {}
}